<template>
  <div class="container">
    <div class="login-wrapper">
      <div class="header">重置密码</div>
      <div class="form-wrapper">
        <div class="input-group">
          <input v-model="email" type="email" placeholder="邮箱" class="input-item" required>
        </div>
        <input v-model="password" type="password" name="password" placeholder="密码" class="input-item">
        <input v-model="repassword" type="password" name="repassword" placeholder="再次确认密码" class="input-item">

        <div class="input-group">
          <input v-model="code" type="code" placeholder="验证码" class="input-item" required>
        </div>
        <button class="btn" @click.prevent="askCode">发送验证码</button>

        <button type="submit" class="btn" @click="handleReset">重置</button>
        <button class="btn" @click="goBack">Back</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Register',
  data() {
    return {
      password: '',
      email: '',
      code: ''
    }
  },
  methods: {
    askCode() {
      var axios = require('axios')

      var config = {
        method: 'get',
        url: 'http://1.92.204.101:5000/auth/reset_verify',
        headers: {
          'Content-Type': 'application/json'
        },
        params: {
          email: this.email
        }
      }

      axios(config)
        .then(function(response) {
          console.log(JSON.stringify(response.data))
        })
        .catch(function(error) {
          console.log(error)
        })
    },
    handleReset() {
      var axios = require('axios')
      var data = JSON.stringify({
        email: this.email,
        password: this.password,
        code: this.code
      })

      var config = {
        method: 'post',
        url: 'http://1.92.204.101:5000/auth/reset_password',
        headers: {
          'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
          'Content-Type': 'application/json'
        },
        data: data
      }

      axios(config)
        .then(function(response) {
          console.log(JSON.stringify(response.data))
        })
        .catch(function(error) {
          console.log(error)
        })
    },

    goBack() {
      this.$router.push({ path: '/' })
    }
  }
}
</script>

  <style scoped>
  html, body {
    height: 100%;
    margin: 0;
    font-family: 'Arial', sans-serif;
  }

  .container {
    height: 100%;
    width: 100%;
    background-image: linear-gradient(to right, #fbc2eb, #a6c1ee);
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .login-wrapper {
    background-color: #fff;
    width: 358px;
    height: 588px;
    border-radius: 15px;
    padding: 0 50px;
  }

  .header {
    font-size: 38px;
    font-weight: bold;
    text-align: center;
    margin-top: 50px; /* 调整头部的上边距 */
  }

  .form-wrapper {
    margin-top: 30px; /* 调整表单区域的上边距 */
  }

  .input-group {
    margin-bottom: 20px;
  }

  .input-item {
    display: block;
    width: 100%;
    margin-bottom: 10px; /* 调整输入框的下边距 */
    border: none;
    border-bottom: 1px solid rgb(128, 125, 125);
    padding: 10px;
    font-size: 15px;
    outline: none;
  }

  .input-item::placeholder {
    text-transform: uppercase;
  }

  .btn {
    text-align: center;
    padding: 12px 0;
    width: 100%;
    margin-top: 20px; /* 调整按钮的上边距 */
    background-image: linear-gradient(to right, #a6c1ee, #fbc2eb);
    color: #fff;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: background-color 0.3s ease;
  }

  .btn:hover {
    background-color: #0e8e85; /* 修改按钮悬停时的背景色 */
  }

  .label {
    font-size: 14px;
    margin-bottom: 5px;
  }

  </style>
